package com.kellycheung.chicken_go_go;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class GameMain extends Activity {
	protected GameEngine geMain;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
        
        try {
	        if ( this.geMain == null ) {
		        this.geMain = new GameEngine( this );
		        this.geMain.addToNextScene( new GameTitle( this.geMain , null ) );
	        }
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onCreate" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
    @Override
    protected void onDestroy() {
    	try {
	    	if ( this.geMain != null ) {
	    		this.geMain.isGameEnded = true;
	    		this.geMain.destroy();
	    	}
	    	
	    	super.onDestroy();
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onDestroy" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
    @Override
    protected void onResume() {
    	try {
	    	if ( this.geMain != null ) {
	    		this.geMain.onResume();
	    	}
	    	
	    	super.onResume();
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onResume" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
    @Override
    protected void onPause() {
    	try {
	    	if ( this.geMain != null ) {
	    		this.geMain.onPause();
	    	}
	    	
	    	super.onPause();
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onPause" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
    @Override
    public void onNewIntent( Intent p_i ) {
    	try {
	    	if ( this.geMain != null ) {
	    		this.geMain.onNewIntent( p_i );
	    	}
	    	
	    	super.onNewIntent( p_i );
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onNewIntent" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
    @Override
	public void onBackPressed() {
    	try {
	    	if ( this.geMain != null ) {
	    		this.geMain.backButtonHandler();
	    	}
	    	else {
	    		this.onBackPressedSuper();
	    	}
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onBackPressed" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
    
	public void onBackPressedSuper() {
		try {
	    	super.onBackPressed();
		} catch ( Exception p_e ) {
			// TODO Auto-generated catch block
			GameUtil.LogMsg( this , "GameMain.onBackPressedSuper" );
			GameUtil.ErrorHandler( this , p_e );
		}
    }
}
